<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <button>按钮</button>
    <ul class="fruit-list">
        <li>香蕉</li>
        <li>苹果</li>
        <li>鸭梨</li>
    </ul>
    <script>
        let btn = document.querySelector('button');
        let ul = document.querySelector('ul');
        let inp = document.querySelector('input');
        let list = document.querySelectorAll('.fruit-list li')
        btn.onclick = function(){
            let value = inp.value
            let li = document.createElement("li");
            let txt = document.createTextNode(value) //获取输入的input里得文本节点
            ul.appendChild(li);  //添加列表
            li.appendChild(txt);  //添加文本
        }

        for(let i in list){
            list[i].onclick = function(){
                ul.removeChild(this);   //删除列表
            }
        }
    </script>
</body>
</html>